<?php
/**
 * Created by PhpStorm.
 * User: tangyunfei
 * Date: 2018/11/14
 * Time: 11:02
 */
class CommonsAction extends Action{
    protected  $cityid;

    protected  $cityname;

    protected  $cateid;
    protected  $catepath;


    protected  $cityinfo;

    protected  $areaid;

    protected  $areainfo;

    protected  $uinfo;
    public $domain = "www";
    function __construct()
    {
        parent::__construct();

        $domain = $_SERVER['HTTP_HOST'];
        $arr = explode(".", $domain);
        $this->domain = $arr[0];

        $this->assign("city",$this->domain);
        $cityinfo = M('City')->where("pinyin='".$this->domain."'")->find();
        $this->cityid = $cityinfo['id'];
        if(S('citylist')){
            $citylist = S('citylist');

        }else{
            $Data=M('City');

            $temp=$Data->where('cid=0 AND status=0')->select();

            foreach ($temp as $v){

                $v['city'] = M('City')->where("cid=".$v['id']." AND status=0")->select();

                $citylist[]=$v;

            }
            S("citylist",$citylist,360);
        }

        $this->assign('citylist',$citylist);
        $this->assign("cityid",$cityinfo['id']);
        if(empty($cityinfo)){
            $this->assign("cityname","全国");
        }else{
            $this->assign("cityname",$cityinfo['city']);
        }

        $config = M('Config')->where("id=1")->find();

        $this->assign("config",$config);
        $cid = $_GET['cid'];


        if(empty($cid)){

            $this->cateid =0;

        }else{
           $arr =  explode("/",$cid);

            if(count($arr)==1){
                 //没有地区
                $this->catepath = $arr[0];
                $this->areaid = "";

                $this->cateid = M('Category')->where("path='".$cid."'")->getField("id");

            }else{
                //有地区
                $this->areaid = M('Area')->where("pinyin='".$arr[0]."'")->getField("id");



                $this->cateid = M('Category')->where("path='".$arr[1]."'")->getField("id");
                $this->catepath = $arr[1];
            }


        }


        $this->assign("cateid",$this->cateid);
        $this->assign("catepath",$this->catepath);

        $this->assign("areaid",$this->areaid);

        $cate = M('Category')->select();
        $this->assign("cate",$cate);


        $this->uinfo = checkUserCookie();

        $this->assign("uinfo",$this->uinfo);

    }

}